<?php
import("Weixin.Util.jssdk");
$jssdk = new JSSDK("wx1509e46e90775fe4", "203f4fefd0fc676e1e7c28f28a9ccec5");
$signPackage = $jssdk->GetSignPackage();
?>
<html lang="zh-CN" id="html">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <link href="__CSS__/materialize.min.css" rel="stylesheet">
    <link href="__CSS__/check-result.css" rel="stylesheet">
    <script src="__JS__/jquery.min.js"></script>
    <script src="__JS__/materialize.min.js"></script>
    <title>填写完成</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <span class="center-align"><?php echo $word;?></span>
            <a id="scanQRCode" class="btn btn-large waves-effect waves-light blue">
                <strong>检测下一个</strong>
            </a>
            <a class="btn btn-large waves-effect waves-light blue" href="{:U('Manage/detection')}"><strong>返回</strong></a>
        </div>
    </div>
</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"> </script>
<script>
  wx.config({
    debug: false,
    appId: '<?php echo $signPackage["appId"];?>', 
    timestamp: <?php echo $signPackage["timestamp"];?>,
    nonceStr: '<?php echo $signPackage["nonceStr"];?>', 
    signature: '<?php echo $signPackage["signature"];?>',
    jsApiList: [
      //'checkJsApi',
      'scanQRCode',   //巡检-act:act2
    ]
  });

    wx.ready(function(){

        function cutstr(text,start,end){
          var s = text.indexOf(start)
          if(s>-1){
          var text2 = text.substr(s+start.length);
          var s2 = text2.indexOf(end);
          if(s2>-1){
          result = text2.substr(0,s2);
          }else result = '';
          }else result = '';
          return result;
        }

        function redirecturl(result,act){
            var serve = "http://weixin.yiyikefu.com/index.php";
            var myArray = result.split('hospid=');//2
            var devicecode = cutstr(result,'hdevice_code=','&hospid');
            var url = serve+"?m=weixin&c=manage&a=getqrcodemsg&hdevice_code="+devicecode+"&hospid="+myArray[1]+"&action="+act;
            $('#html').load(url);
        }
        //巡检
        document.querySelector('#scanQRCode').onclick = function () {
          wx.scanQRCode({
            needResult: 1,
            desc: 'scanQRCode desc',
            success: function (res) {
              var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
              var act = "xunjian";
              redirecturl(result,act);
            }
          });
        };
    });

    wx.error(function (res) {
      alert(res.errMsg);
    });
</script>
</html>